package com.atguigu.lease.common.sms;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * Package: com.atguigu.lease.common.sms
 *
 * @Description:
 * @Author xiongkunYang
 * @Create 2025/4/28 13:57
 */
@SpringBootConfiguration
@EnableConfigurationProperties({AliyunSmsProperties.class})
public class AliyunSmsConfiguration {

    private final AliyunSmsProperties properties;

    public AliyunSmsConfiguration(AliyunSmsProperties properties) {
        this.properties = properties;
    }

    @Bean
    public Client smsClient() throws Exception {
        return new Client(new Config()
                .setAccessKeyId(properties.getAccessKeyId())
                .setAccessKeySecret(properties.getAccessKeySecret())
                .setEndpoint(properties.getEndpoint()));
    }
}